﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using zhangmenren.IService;
using zhangmenren.Models;
using zhangmenren.Service;
using zhangmenren.ViewModel;

namespace zhangmenren.Areas.Admin.Controllers
{
    [Area(areaName: "Admin")]
    public class RealController : Controller
    {
        private IRealService realService;
        public RealController(IRealService _realService)
        {
            realService = _realService;
        }


        public IActionResult Index()
        {
            return View();
        }
        public async Task<string> GetRealUser()
        {
                int total = 0;
                IEnumerable<RealMode> dataList = null;
                dataList = await realService.Selelct();
                if (dataList.Any())
                {
                    total = dataList.Count();
                }
                return JsonConvert.SerializeObject(new { code = "0", msg = "查询成功", data = dataList, count = total });

        }

        [HttpPost]
        public async Task<JsonResult> UpState(int id, int state = 1)
        {
            var result = await realService.UpState(id, state);

            return Json(new { state = "ok", msg = "修改成功" });
        }

        [HttpPost]
        public JsonResult Del(int id = 0)
        {
            if (id != 0)
            {
                var result = realService.Del(id);
                return Json(new { state = "ok", msg = "删除成功" });
            }
            return Json(new { state = "fail", msg = "标识错误" });
        }

    }
}